package cate.game.play.skill.passive.fairy;

import cate.common.table.d.GDCamp;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.skill.Skill;
import cate.game.play.skill.passive.PassiveHandler;

import java.util.Comparator;

/**
 * 效果2：速度提升100点，”生命动力”额外提升"心灵治愈"15%暴击伤害，如目标为水系英雄则提升20%
 * 效果3：战斗开始为攻击最高单位附加[不离]， 每回合开始前恢复生命之水70%攻击力的生命值，”祈愿之福"优先复活[不离]目标且无视禁活，不可驱散持续至战斗结束
 */
public class 生命之水灵器PH extends PassiveHandler {


	private String 心灵治愈标签;

	private int 暴击buff;

	private int 水系buff;

	private int 不离buff;

	private String 祈愿之福标签;

	//心灵治愈标签=心灵治愈&暴击buff=？？&水系buff=？？&
	//不离buff=？？&祈愿之福标签=祈愿之福
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		心灵治愈标签 = args.get("心灵治愈标签");
		暴击buff = args.getInt("暴击buff", 0);
		水系buff = args.getInt("水系buff", 0);
		不离buff = args.getInt("不离buff", 0);
		祈愿之福标签 = args.get("祈愿之福标签");
	}


	@Override
	public void onSkillDone(SkillActionCtx action) {
		if (action.getSkill().cfg.containTag(心灵治愈标签)) {
			for (Fighter target : action.getTargets()) {
				if (target.getCamp() == GDCamp.Type.C1) {
					target.buff.tryAddByTid(action, skill.owner, 水系buff);
				} else {
					target.buff.tryAddByTid(action, skill.owner, 暴击buff);
				}
			}
		}
	}

	private int friendPid;

	@Override
	public void onFirstEnter(ActionCtx action) {
		if (不离buff > 0) {
			skill.owner.getFightTeam().getFightersAlive().stream().min(Comparator.comparing(f -> -f.attr.total().attTotal())).
					ifPresent(f -> {
						friendPid = f.getPid();
						f.buff.tryAddByTid(action, skill.owner, 不离buff);
					});
		}
	}

	@Override
	public void beforeSelectTargets(MoveCtx move, Skill skill) {
		if (skill.cfg.containTag(祈愿之福标签) && friendPid > 0) {
			skill.param.addTopPriorityPid(friendPid);
			skill.param.setIgnNoRebirth(true);
		}
	}
}
